package com.px.device.controller;

import com.px.common.annotation.Log;
import com.px.common.core.controller.BaseController;
import com.px.common.core.domain.AjaxResult;
import com.px.common.core.page.TableDataInfo;
import com.px.common.enums.BusinessType;
import com.px.common.utils.poi.ExcelUtil;
import com.px.system.domain.DroneInfo;
import com.px.device.service.IDroneInfoService;
import com.px.framework.aes.AesSecurityParameter;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 无人机信息Controller
 * 
 * @author WRJ
 * @date 2024-08
 */
@Api("无人机信息")
@RestController
@RequestMapping("/device/DroneInfo")
public class DroneInfoController extends BaseController
{
    @Autowired
    private IDroneInfoService droneInfoService;

    /**
     * 查询无人机信息列表
     */
    @ApiOperation("查询无人机信息列表")
    @PreAuthorize("@ss.hasPermi('device:DroneInfo:query')")
    @GetMapping("/list")
    @AesSecurityParameter(outEncode = true)
    public TableDataInfo list(DroneInfo droneInfo)
    {
        startPage();
        List<DroneInfo> list = droneInfoService.selectDroneInfoList(droneInfo);
        return getDataTable(list);
    }

    /**
     * 导出无人机信息列表
     */
    @ApiOperation("导出无人机信息列表")
    @PreAuthorize("@ss.hasPermi('device:DroneInfo:query')")
    @Log(title = "无人机信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @AesSecurityParameter
    public void export(HttpServletResponse response, DroneInfo droneInfo)
    {
        List<DroneInfo> list = droneInfoService.selectDroneInfoList(droneInfo);
        ExcelUtil<DroneInfo> util = new ExcelUtil<DroneInfo>(DroneInfo.class);
        util.exportExcel(response, list, "无人机信息数据");
    }

    /**
     * 获取无人机信息详细信息
     */
    @ApiOperation("获取无人机信息详细信息")
    @PreAuthorize("@ss.hasPermi('device:DroneInfo:query')")
    @GetMapping(value = "/{id}")
    @AesSecurityParameter(outEncode = true)
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(droneInfoService.selectDroneInfoById(id));
    }

    /**
     * 新增无人机信息
     */
    @ApiOperation("新增无人机信息")
    @PreAuthorize("@ss.hasPermi('device:DroneInfo:edit')")
    @Log(title = "无人机信息", businessType = BusinessType.INSERT)
    @PostMapping
    @AesSecurityParameter(outEncode = true)
    public AjaxResult add(@RequestBody DroneInfo droneInfo)
    {
        return toAjax(droneInfoService.insertDroneInfo(droneInfo));
    }

    /**
     * 修改无人机信息
     */
    @ApiOperation("修改无人机信息")
    @PreAuthorize("@ss.hasPermi('device:DroneInfo:edit')")
    @Log(title = "无人机信息", businessType = BusinessType.UPDATE)
    @PutMapping
    @AesSecurityParameter(outEncode = true)
    public AjaxResult edit(@RequestBody DroneInfo droneInfo)
    {
        return toAjax(droneInfoService.updateDroneInfo(droneInfo));
    }

    /**
     * 删除无人机信息
     */
    @ApiOperation("删除无人机信息")
    @PreAuthorize("@ss.hasPermi('device:DroneInfo:remove')")
    @Log(title = "无人机信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    @AesSecurityParameter(outEncode = true)
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(droneInfoService.deleteDroneInfoByIds(ids));
    }
}
